package com.ruoyi.common.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.mapper.TrainingInstitutionInfomationMapper;
import com.ruoyi.common.domain.TrainingInstitutionInfomation;
import com.ruoyi.common.service.ITrainingInstitutionInfomationService;

/**
 * 培训机构基本信息Service业务层处理
 * 
 * @author wusihao
 * @date 2023-03-27
 */
@Service
public class TrainingInstitutionInfomationServiceImpl extends ServiceImpl<TrainingInstitutionInfomationMapper, TrainingInstitutionInfomation> implements ITrainingInstitutionInfomationService
{
    @Autowired
    private TrainingInstitutionInfomationMapper trainingInstitutionInfomationMapper;

    /**
     * 查询培训机构基本信息
     * 
     * @param id 培训机构基本信息主键
     * @return 培训机构基本信息
     */
    @Override
    public TrainingInstitutionInfomation selectTrainingInstitutionInfomationById(Long id)
    {
        return trainingInstitutionInfomationMapper.selectTrainingInstitutionInfomationById(id);
    }


    /**
     * 新增培训机构基本信息
     * 
     * @param trainingInstitutionInfomation 培训机构基本信息
     * @return 结果
     */
    @Override
    public int insertTrainingInstitutionInfomation(TrainingInstitutionInfomation trainingInstitutionInfomation)
    {
        trainingInstitutionInfomation.setCreateId(SecurityUtils.getUserId());
        trainingInstitutionInfomation.setCreateTime(DateUtils.getNowDate());

        return trainingInstitutionInfomationMapper.insert(trainingInstitutionInfomation);
    }

    /**
     * 修改培训机构基本信息
     * 
     * @param trainingInstitutionInfomation 培训机构基本信息
     * @return 结果
     */
    @Override
    public int updateTrainingInstitutionInfomation(TrainingInstitutionInfomation trainingInstitutionInfomation)
    {
        trainingInstitutionInfomation.setUpdateId(SecurityUtils.getUserId());
        trainingInstitutionInfomation.setUpdateTime(DateUtils.getNowDate());
        return trainingInstitutionInfomationMapper.updateTrainingInstitutionInfomation(trainingInstitutionInfomation);
    }

    /**
     * 批量删除培训机构基本信息
     * 
     * @param ids 需要删除的培训机构基本信息主键
     * @return 结果
     */
    @Override
    public int deleteTrainingInstitutionInfomationByIds(Long[] ids)
    {
        return trainingInstitutionInfomationMapper.deleteTrainingInstitutionInfomationByIds(ids);
    }

    /**
     * 删除培训机构基本信息信息
     * 
     * @param id 培训机构基本信息主键
     * @return 结果
     */
    @Override
    public int deleteTrainingInstitutionInfomationById(Long id)
    {
        return trainingInstitutionInfomationMapper.deleteTrainingInstitutionInfomationById(id);
    }

    // 查询各个账号人员基本信息
    @Override
    public List<TrainingInstitutionInfomation> selectTrainingInstitutionpeixunjigouInfomationList(TrainingInstitutionInfomation trainingInstitutionInfomation) {
        QueryWrapper<TrainingInstitutionInfomation> trainingInstitutionInfomationQueryWrapper = new QueryWrapper<>();
        trainingInstitutionInfomationQueryWrapper.eq("create_id", SecurityUtils.getUserId());
        TrainingInstitutionInfomation selectOne = trainingInstitutionInfomationMapper.selectOne(trainingInstitutionInfomationQueryWrapper);
        if (selectOne == null) return new ArrayList<>();
        List<TrainingInstitutionInfomation> trainingInstitutionInfomations = new ArrayList<>();
        trainingInstitutionInfomations.add(selectOne);
        return  trainingInstitutionInfomations;
    }

}
